import React from 'react';
import { Button } from '@teamix/ui';
import { navigateOpen } from 'utils/router';
import './index.scss';
import intl from '../../../../../../locale';

export default class OauthSuccessPage extends React.Component {
  componentDidMount() {
    // this.close();
  }

  close = () => {
    const { userAgent } = navigator;
    if (userAgent.indexOf('Firefox') !== -1 || userAgent.indexOf('Chrome') !== -1) {
      window.location.href = 'about:blank';
      window.close();
    } else {
      navigateOpen('', '_self');
      window.close();
    }
  };

  render() {
    return (
      <div className="callback-container">
        {intl.get({
          id: 'code-assets.pages.callback.IfTheAuthorizationIsSuccessful',
          defaultMessage: '授权成功，当前页面即将自动关闭 或者',
        })}

        <Button
          onClick={() => {
            window.close();
          }}
        >
          {intl.get({ id: 'code-assets.pages.callback.Closed', defaultMessage: '关闭' })}
        </Button>
      </div>
    );
  }
}
